/**
 * 获取日期时间
 * @returns 日期时间
 */
function datetime(){
    let date = new Date()
    let dateStr = getDate_(date);
    let timeStr = getTime_(date);
    let time = dateStr +" "+ timeStr;
    return time;
}

/**
 * 获取当前日期
 * @returns 日期
 */
function date(){
    return getDate_(new Date());
}


/**
 * 获取当前时间
 * @returns 时间
 */
function time(){
    return getTime_(new Date());
}


/**
 * 获取日期（私有方法）
 * 格式: YYYY-MM-DD
 */
function getDate_(date){
    let year = date.getFullYear();
    let month = padZero(date.getMonth()+1);
    let day = padZero(date.getDay());
    let time = year + "-" + month + "-" + day;
    return time;
}

/**
 * 获取时间（私有方法）
 * 格式: HH:mm:ss
 */
function getTime_(date){
    let hour = padZero(date.getHours());
    let minute = padZero(date.getMinutes());
    let second = padZero(date.getSeconds());
    let time = hour + ":" + minute + ":" +second; 
    return time;
}




/**
 * 补零函数
 */ 
function padZero(n){
    if(n<=9){
        return "0"+n;
    }
    return n;
}

module.exports = {
    datetime,
    date,
    time
}